/**
 * Alipay.com Inc.
 * Copyright (c) 2004-2011 All Rights Reserved.
 */
package com.alipay.supergw.common.dal.share_supergw.auto.ibatis;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
import com.alipay.supergw.common.dal.share_supergw.auto.daointerface.ClusterDAO;
import com.alipay.supergw.common.dal.share_supergw.auto.dataobject.ClusterDO;
import java.util.List;
import org.springframework.dao.DataAccessException;
import java.util.Map;
import java.util.HashMap;

/**
 * An ibatis based implementation of dao interface <tt>com.alipay.supergw.common.dal.share_supergw.auto.daointerface.ClusterDAO</tt>.
 *
 * This file is generated by <tt>supergw-dalgen</tt>, a DAL (Data Access Layer)
 * code generation utility specially developed for <tt>supergw</tt> project.
 * 
 * PLEASE DO NOT MODIFY THIS FILE MANUALLY, or else your modification may
 * be OVERWRITTEN by someone else. To modify the file, you should go to 
 * directory <tt>(project-home)/dalgen</tt>, and 
 * find the corresponding configuration file (<tt>tables/sgw_cluster.xml</tt>). 
 * Modify the configuration file according to your needs, then run <tt>supergw-dalgen</tt> 
 * to generate this file.
 */
public class IbatisClusterDAO extends SqlMapClientDaoSupport implements ClusterDAO {

    /**
     *  Query DB table <tt>sgw_cluster</tt> for records.
     *
     *  <p>
     *  Description for this operation is<br>
     *  <tt></tt>
     *  <p>
     *  The sql statement for this operation is <br>
     *  <tt>select cluster_id, domain_name, cluster_addr, gmt_create, gmt_modified from sgw_cluster</tt>
     *
     *	@return List<ClusterDO>
     *	@throws DataAccessException
     */
    @SuppressWarnings("unchecked")
    public List<ClusterDO> loadAll() throws DataAccessException {

        return getSqlMapClientTemplate().queryForList("MS-CLUSTER-LOAD-ALL", null);

    }

    /**
     *  Query DB table <tt>sgw_cluster</tt> for records.
     *
     *  <p>
     *  Description for this operation is<br>
     *  <tt></tt>
     *  <p>
     *  The sql statement for this operation is <br>
     *  <tt>select cluster_id, domain_name, gmt_create, gmt_modified, cluster_addr from sgw_cluster where (cluster_id = ?)</tt>
     *
     *	@param clusterId
     *	@return ClusterDO
     *	@throws DataAccessException
     */
    public ClusterDO loadByClusterId(String clusterId) throws DataAccessException {

        return (ClusterDO) getSqlMapClientTemplate().queryForObject(
            "MS-CLUSTER-LOAD-BY-CLUSTER-ID", clusterId);

    }

    /**
     *  Query DB table <tt>sgw_cluster</tt> for records.
     *
     *  <p>
     *  Description for this operation is<br>
     *  <tt></tt>
     *  <p>
     *  The sql statement for this operation is <br>
     *  <tt>select cluster_id, domain_name, gmt_create, gmt_modified, cluster_addr from sgw_cluster where ((cluster_id = ?) AND (domain_name = ?))</tt>
     *
     *	@param clusterId
     *	@param domainName
     *	@return List<ClusterDO>
     *	@throws DataAccessException
     */
    @SuppressWarnings({ "rawtypes", "unchecked" })
    public List<ClusterDO> select(String clusterId, String domainName) throws DataAccessException {
        Map param = new HashMap();

        param.put("clusterId", clusterId);
        param.put("domainName", domainName);

        return getSqlMapClientTemplate().queryForList("MS-CLUSTER-SELECT", param);

    }

    /**
     *  Insert one <tt>ClusterDO</tt> object to DB table <tt>sgw_cluster</tt>, return primary key
     *
     *  <p>
     *  Description for this operation is<br>
     *  <tt></tt>
     *  <p>
     *  The sql statement for this operation is <br>
     *  <tt>insert into sgw_cluster(cluster_id,domain_name,gmt_create,gmt_modified,cluster_addr) values (?, ?, sysdate, sysdate, ?)</tt>
     *
     *	@param cluster
     *	@return String
     *	@throws DataAccessException
     */
    public String insert(ClusterDO cluster) throws DataAccessException {
        if (cluster == null) {
            throw new IllegalArgumentException("Can't insert a null data object into db.");
        }

        getSqlMapClientTemplate().insert("MS-CLUSTER-INSERT", cluster);

        return cluster.getClusterId();
    }

    /**
     *  Update DB table <tt>sgw_cluster</tt>.
     *
     *  <p>
     *  Description for this operation is<br>
     *  <tt></tt>
     *  <p>
     *  The sql statement for this operation is <br>
     *  <tt>update sgw_cluster set domain_name=?, gmt_modified=sysdate, cluster_addr=? where (cluster_id = ?)</tt>
     *
     *	@param domainName
     *	@param clusterAddr
     *	@param clusterId
     *	@return int
     *	@throws DataAccessException
     */
    @SuppressWarnings({ "rawtypes", "unchecked" })
    public int update(String domainName, String clusterAddr, String clusterId)
                                                                              throws DataAccessException {
        Map param = new HashMap();

        param.put("domainName", domainName);
        param.put("clusterAddr", clusterAddr);
        param.put("clusterId", clusterId);

        return getSqlMapClientTemplate().update("MS-CLUSTER-UPDATE", param);
    }

    /**
     *  Delete records from DB table <tt>sgw_cluster</tt>.
     *
     *  <p>
     *  Description for this operation is<br>
     *  <tt></tt>
     *  <p>
     *  The sql statement for this operation is <br>
     *  <tt>delete from sgw_cluster where (cluster_id = ?)</tt>
     *
     *	@param clusterId
     *	@return int
     *	@throws DataAccessException
     */
    public int delete(String clusterId) throws DataAccessException {

        return getSqlMapClientTemplate().delete("MS-CLUSTER-DELETE", clusterId);
    }

}